<template>
  <div>
    <h3>AddItem组件</h3>
    <p>已知库存数: {{ $store.state.num }}</p>
    <button @click="addFn">库存+1</button>
    <button @click="asyncAddNumFn">延迟2秒，库存+5</button>
  </div>
</template>

<script>
export default {
  name: 'AddItem',
  methods: {
    addFn () {
      this.$store.commit('addNum')
    },
    asyncAddNumFn () {
      this.$store.dispatch('asyncAddNum', 5)
    }
  }
}
</script>
